﻿using System;

namespace Yto.Common.Extensions
{
    public static class EventHandlerExtensions
    {
        public static void InvokeEvent(this EventHandler handler, object sender)
        {
            handler.Invoke(sender, EventArgs.Empty);
        }

        public static void InvokeEvent(this EventHandler handler, object sender, EventArgs eventArgs)
        {
            if (handler == null)
            {
                return;
            }

            handler(sender, eventArgs);
        }

        public static void InvokeEvent<TEventArgs>(this EventHandler<TEventArgs> handler, object sender, TEventArgs eventArgs)
            where TEventArgs : EventArgs
        {
            if (handler == null)
            {
                return;
            }

            handler(sender, eventArgs);
        }
    }
}
